// 通过API的形式调用Toast

// 有什么用？
/* 
    1.不用import组件
*/

import CreateAPI from 'vue-create-api';
import Vue from 'vue';
import Toast from '@/components/common/Toast.vue';
import Popup from '@/components/common/Popup.vue';
import GroupDialog from '@/components/shelf/ShelfGroupDialog.vue';

Vue.use(CreateAPI);

/* 
    它会创建这么一个方法
        this.$createToast
            create + 组件名
*/
Vue.createAPI(Toast, true);
Vue.createAPI(Popup, true);
Vue.createAPI(GroupDialog, true);
/* 
        抽象
            !这是原方法
                    onTabClick(item) {
                        this.$createToast({
                            $props: {
                            text: 'Hello api',
                            },
                        }).show();
                    },
 */
Vue.mixin({
  methods: {
    toast(settings) {
      return this.$createToast({
        $props: settings,
      });
    },
    popup(settings) {
      return this.$createPopup({
        $props: settings,
      });
    },
    simpleToast(text) {
      const toast = this.toast({
        text: text,
      });
      toast.show();
      toast.updateText(text);
    },
    dialog() {
      return this.$createGroupDialog();
    },
  },
});
